Skip to content

[wrangler] Preserve serialized error details in castErrorCause - #14906

Open
exKAZUu wants to merge 5 commits into
cloudflare:mainfrom
exKAZUu:fix-cast-error-cause-message
Open

[wrangler] Preserve serialized error details in castErrorCause#14906
exKAZUu wants to merge 5 commits into
cloudflare:mainfrom
exKAZUu:fix-cast-error-cause-message

Conversation

@exKAZUu

@exKAZUu exKAZUu commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Addresses the diagnosability problem reported in #14641 (the underlying keep-alive race itself is tracked separately in that issue).

Errors reported by the ProxyWorker cross a JSON channel, so they always arrive in ProxyController.onProxyWorkerMessage as SerializedError plain objects, never Error instances. castErrorCause() wrapped them in a message-less new Error(), keeping the original report only as an unprinted .cause — so when a transient failure (e.g. Network connection lost. from the kj 5s keep-alive race described in #14641) was treated as fatal, wrangler dev exited with an empty ✘ [ERROR] log and no indication of the actual failure, which reportedly cost multiple users many hours of debugging.

This change makes castErrorCause() rehydrate SerializedError-shaped causes into a real Error, preserving the original message, name and stack (and keeping the serialized nested cause). Behavior for Error instances and other non-Error causes is unchanged.


  • Tests
    • Tests included/updated: unit tests for castErrorCause() covering Error passthrough, rehydration of a JSON-roundtripped serialiseError() payload (message/name/stack preserved), nested cause preservation, and unchanged wrapping of other non-Error values. Plus a ProxyController integration test dispatching a serialized { type: "error" } ProxyWorker message through onProxyWorkerMessage and asserting the emitted error event carries the original message/stack (fails without this fix with expected '' to be 'Network connection lost.').
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: internal error-reporting fix; the only user-visible change is that previously-empty ✘ [ERROR] logs now contain the actual error message.

Open in Devin Review

Errors reported by the ProxyWorker cross a JSON channel and arrive as
SerializedError plain objects. castErrorCause wrapped them in a
message-less new Error(), so the fatal log from emitErrorEvent was an
empty '✘ [ERROR]' with no indication of the actual failure (see cloudflare#14641,
e.g. transient 'Network connection lost.' keep-alive races killing the
whole dev server with an empty error). Rehydrate the serialized
message/name/stack instead.
@exKAZUu
exKAZUu requested a review from workers-devprod as a code owner July 29, 2026 12:47
@changeset-bot

changeset-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a679436

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
wrangler Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Jul 29, 2026
@workers-devprod
workers-devprod requested review from a team and emily-shen and removed request for a team July 29, 2026 12:47
@workers-devprod

workers-devprod commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/fix-cast-error-cause-message.md: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/api/startDevWorker/ProxyController.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/api/startDevWorker/events.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/api/startDevWorker/events.ts: [@cloudflare/wrangler]

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

@pkg-pr-new

pkg-pr-new Bot commented Jul 29, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/autoconfig@14906

@cloudflare/config

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/config@14906

create-cloudflare

npm i https://pkg.pr.new/cloudflare/workers-sdk/create-cloudflare@14906

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/deploy-helpers@14906

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/kv-asset-handler@14906

miniflare

npm i https://pkg.pr.new/cloudflare/workers-sdk/miniflare@14906

@cloudflare/pages-functions

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/pages-functions@14906

@cloudflare/pages-shared

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/pages-shared@14906

@cloudflare/unenv-preset

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/unenv-preset@14906

@cloudflare/vite-plugin

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/vite-plugin@14906

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/vitest-pool-workers@14906

@cloudflare/workers-auth

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/workers-auth@14906

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/workers-editor-shared@14906

@cloudflare/workers-utils

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/workers-utils@14906

wrangler

npm i https://pkg.pr.new/cloudflare/workers-sdk/wrangler@14906

commit: a679436

…ProxyWorkerMessage

Verifies the emitted error event carries the original message/stack after
crossing the JSON channel, guarding against the empty '✘ [ERROR]'
regression from cloudflare#14641.
devin-ai-integration[bot]

This comment was marked as resolved.

exKAZUu and others added 3 commits July 29, 2026 21:59
Review findings: tighten isSerializedError to the exact shape produced by
serialiseError/ProxyWorker (no extra keys) so arbitrary message-bearing
objects keep the wrap-as-cause behavior; skip the own 'cause: undefined'
property that polluted util.format debug logs; recursively rehydrate
serialized cause chains so instanceof-Error cause classifiers work across
the JSON channel.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

2 participants